import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Main4 {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        //构造方法的数字,就是拆分出来的任务个数
        CountDownLatch countDownLatch =new CountDownLatch(20);

        for(int i = 0 ; i < 20;i++){
            int id = i;
            executorService.submit(()->{
                System.out.println("下载任务"+id+"开始执行");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println("下载任务"+id+"结束任务");
                //完毕!!
                countDownLatch.countDown();
            });
        }

            //当countDownLatch收到20个"完成",所有的任务就完成了

            //await= allwait
        countDownLatch.await();

    }



}
